package com.info.zhiduoduo.common.constants.project;

import com.google.common.collect.Lists;
import com.info.zhiduoduo.common.constants.Constants;
import com.info.zhiduoduo.common.constants.entrustmentproject.EntrustProjectState;

import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 统计或计算项目金额时，需要包含的项目状态，不同的项目对应的状态不同。
 * <p>  项目状态：0：草稿、进行中、验收中、已验收、已完成； 1：进行中、验收中、已验收、已完成； 2：验收中、已验收、已完成； 3：已验收、已完成； 4：已完成；
 * <p> 智众包子项目状态：0：已创建、交易中、交易成功、交易失败； 1、2、3：交易中、交易成功、交易失败； 4：交易成功；
 * <p> 委托接单创客团项目：0：已创建、已分配(受托人创客)、支付完成、支付失败； 1、2、3：已分配(受托人创客)、支付完成、支付失败； 4：支付完成
 */
public interface CalcAmountType {

	/** 全部草稿、进行中、验收中、已验收、已完成 */
	int ALL = 0;
	/** 进行中、验收中、已验收、已完成 */
	int PROCESSING = 1;
	/** 验收中、已验收、已完成、 */
	int CHECKING = 2;
	/** 已验收、已完成 */
	int CHECKED = 3;
	/** 已完成 */
	int FINISHED = 4;

	/**
	 * 获取 项目的状态
	 *
	 * @param calcAmountType
	 * @return
	 */
	static String getZhiduoduoProjectStates(int calcAmountType) {
		List<Integer> states;
		switch (calcAmountType) {
			case PROCESSING:
				states = Lists.newArrayList(CompanyProjectState.PROCESSING, CompanyProjectState.CHECKING, CompanyProjectState.CHECKED,
						CompanyProjectState.WAIT_OFFLINE_PAY, CompanyProjectState.COMPLETED);
				break;
			case CHECKING:
				states = Lists.newArrayList(CompanyProjectState.CHECKING, CompanyProjectState.CHECKED,
						CompanyProjectState.WAIT_OFFLINE_PAY,
						CompanyProjectState.COMPLETED);
				break;
			case CHECKED:
				states = Lists.newArrayList(CompanyProjectState.CHECKED, CompanyProjectState.WAIT_OFFLINE_PAY,
						CompanyProjectState.COMPLETED);
				break;
			case FINISHED:
				states = Lists.newArrayList(CompanyProjectState.WAIT_OFFLINE_PAY, CompanyProjectState.COMPLETED);
				break;
			case ALL:
			default:
				states = Lists.newArrayList(CompanyProjectState.DRAFT, CompanyProjectState.SUBMITTED, CompanyProjectState.BIDDING,
						CompanyProjectState.PROCESSING, CompanyProjectState.CHECKING, CompanyProjectState.CHECKED,
						CompanyProjectState.WAIT_OFFLINE_PAY, CompanyProjectState.COMPLETED);
		}
		return StringUtils.join(states, ",");
	}

	/**
	 * 获取智众包子项目状态
	 *
	 * @param calcAmountType
	 * @return
	 */
	static String getCrowdsourceProjectStates(int calcAmountType) {
		List<Integer> states;
		switch (calcAmountType) {
			case PROCESSING:
			case CHECKING:
			case CHECKED:
				states = Lists.newArrayList(Constants.CROWDSOURCE_BATCH_ITEM_PAYING, Constants.CROWDSOURCE_BATCH_ITEM_PAID,
						Constants.CROWDSOURCE_BATCH_ITEM_FAILED);
				break;
			case FINISHED:
				states = Lists.newArrayList(Constants.CROWDSOURCE_BATCH_ITEM_PAID);
				break;
			case ALL:
			default:
				states = Lists.newArrayList(Constants.CROWDSOURCE_BATCH_ITEM_CREATED, Constants.CROWDSOURCE_BATCH_ITEM_PAYING,
						Constants.CROWDSOURCE_BATCH_ITEM_PAID, Constants.CROWDSOURCE_BATCH_ITEM_FAILED);
				break;
		}
		return StringUtils.join(states, ",");
	}

	/**
	 * 获取委托接单、创客团子项目的状态
	 *
	 * @param calcAmountType
	 * @return
	 */
	static String getEntrustProjectStates(int calcAmountType) {
		List<Integer> states;
		switch (calcAmountType) {
			case PROCESSING:
			case CHECKING:
			case CHECKED:
				states = Lists.newArrayList(EntrustProjectState.DISPATCHED, EntrustProjectState.FINISH, EntrustProjectState.FAIL);
				break;
			case FINISHED:
				states = Lists.newArrayList(EntrustProjectState.FINISH);
				break;
			case ALL:
			default:
				states = Lists.newArrayList(EntrustProjectState.CREATED, EntrustProjectState.DISPATCHED, EntrustProjectState.FINISH,
						EntrustProjectState.FAIL);
				break;
		}
		return StringUtils.join(states, ",");
	}
}
